﻿using Marmat.Forms.Views.DataGrid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Marmat.Forms.Local
{
    partial class DataGrid
    {
        /// <summary>
        /// 
        /// </summary>
        [Editor("Marmat.Forms.Design.DataGridUITypeEditor", typeof(System.Drawing.Design.UITypeEditor))]
        [EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Relation Relation
        {
            get
            {
                if (this._Relation == null)
                    this._Relation = new Relation(this);
                return this._Relation;
            }
        }
        private Relation _Relation;


        [Browsable(false)]
        public List<Relation> ChildRelation
        {
            get
            {
                if (m_ChildRelation == null)
                    m_ChildRelation = new List<Relation>();
                return m_ChildRelation;
            }
        }
        private List<Relation> m_ChildRelation;

        /// <summary>
        /// 返回 Table 的保存集合
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [Localizable(true)]
        [NotifyParentProperty(true)]
        [Category("数据")]
        [Description("返回 Table 的保存集合")]
        [Editor("Marmat.Forms.Design.DataGridUITypeEditor", typeof(System.Drawing.Design.UITypeEditor))]
        public SaveProjectCollection SaveProjects
        {
            get
            {
                if (m_SaveProjects == null)
                    m_SaveProjects = new SaveProjectCollection(this);
                return m_SaveProjects;
            }
        }
        private SaveProjectCollection m_SaveProjects;

        /// <summary>
        /// 获取或设置是否启用分页加载
        /// </summary>
        [DefaultValue(false)]
        [Category("加载·分页")]
        [Description("获取或设置是否启用分页加载。")]
        public bool ShowPagingLoad
        {
            get => this.m_ShowPagingLoad;
            set
            {
                this.m_ShowPagingLoad = value;
                this.pageControl1.Visible = value;
            }
        }
        private bool m_ShowPagingLoad = false;

        /// <summary>
        /// 则用于指定每页的行数
        /// </summary>
        [DefaultValue(100)]
        [Category("加载·分页")]
        [Description("则用于指定每页的行数。")]
        public int LoadTop
        {
            get => m_LoadTop;
            set
            {
                m_LoadTop = value;
                this.pageControl1.LoadTop = this.LoadTop;
            }
        }
        private int m_LoadTop = 100;

        /// <summary>
        /// 指定要加载的页号
        /// </summary>
        [DefaultValue(0)]
        [Category("加载·分页")]
        [Description("指定要加载的页号。")]
        public int LoadPage { get; set; } = 0;

        /// <summary>
        /// 字符型，用于指定分页加载依据列
        /// </summary>
        [DefaultValue(null)]
        [Category("加载·分页")]
        [Description("字符型，用于指定分页加载依据列。")]
        public string LoadOver { get; set; }

        /// <summary>
        /// 逻辑型，是否倒序加载，即是否先加载新数据，此属性只有在分页加载的时候才有效。
        /// </summary>
        [DefaultValue(false)]
        [Category("加载·分页")]
        [Description("逻辑型，是否倒序加载，即是否先加载新数据，此属性只有在分页加载的时候才有效。")]
        public bool LoadReverse { get; set; }

        /// <summary>
        /// 整数型，返回分页加载时，总的可加载总页数。
        /// </summary>
        [Browsable(false)]
        protected internal int TotalPages { get; }

        /// <summary>
        /// 或者或设置 Table 对应的数据源名称
        /// </summary>
        [DefaultValue(null)]
        [Editor("Marmat.Forms.Design.DataGridUITypeEditor", typeof(System.Drawing.Design.UITypeEditor))]
        [Category("加载"), Description("设置或返回绑定的数据源名称")]
        public string ConnectionName { get; set; }

        /// <summary>
        /// 获取或设置 Table 加载时对应的数据库后台表名
        /// </summary>
        [Editor("Marmat.Forms.Design.DataGridUITypeEditor", typeof(System.Drawing.Design.UITypeEditor))]
        [DefaultValue(null)]
        [Category("加载"), Description("获取或设置 Table 加载时对应的数据库后台表名。")]
        public string LoadTableName { get; set; }

        /// <summary>
        /// 获取或设置 Table 的加载条件
        /// </summary>
        [DefaultValue(null)]
        [Category("加载")]
        [Description("获取或设置 Table 的加载条件。")]
        public string LoadFilter { get; set; }

        /// <summary>
        /// 字符型，指定加载数据的顺序
        /// </summary>
        [DefaultValue(null)]
        [Category("加载")]
        [Description("字符型，指定加载数据的顺序。")]
        public string LoadOrder { get; set; }

        /// <summary>
        /// 返回 DataGrid 的列集合。
        /// </summary>
        [Editor("Marmat.Forms.Design.DataGridUITypeEditor", typeof(System.Drawing.Design.UITypeEditor))]
        public override ColumnCollection Columns => base.Columns;
    }
}
